package com.example.login.controller;

import com.example.login.entity.User;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.login.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    public UserService userService;

    @RequestMapping("/login")
    public JSONObject login(String name, String pwd) {
        User user = userService.loginByNameAndPwd(name, pwd);
        System.out.println(name + " " + pwd);
        if (null != user){
            return (JSONObject) JSON.toJSON(user);
        } else {
            return  null;
        }
    }
}
